package com.yupi.yupicturebackend.config;

import com.github.benmanes.caffeine.cache.Caffeine;
import org.springframework.cache.CacheManager;
import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;

@Configuration
public class CacheConfig {

    @Bean
    public CacheManager cacheManager() {
        CaffeineCacheManager cacheManager = new CaffeineCacheManager("picturePage");
        // 配置Caffeine缓存策略
        cacheManager.setCaffeine(Caffeine.newBuilder()
                .initialCapacity(1024) //初始缓存数量
                .maximumSize(10000) // 最大缓存数量
                .expireAfterWrite(Duration.ofMinutes(5)));// 写入后5分钟过期
        return cacheManager;
    }

}
